﻿using UnityEngine;
using System.Collections;

public class FX_color_loop : MonoBehaviour {

	public int matSlot = 0;
	public float duration = 1.0f;
	public bool loop = false;
	
	float timer = 0;
	
	[SerializeField]
	Gradient colorGradient;
	
	void Update ()
	{
		if( this.renderer.materials.Length <= matSlot )
		{
			return;
		}

		Color color = colorGradient.Evaluate(timer);
		
		renderer.materials[matSlot].SetColor("_TintColor",color);
		
		timer += Time.deltaTime/duration;

		if (loop) {
			if(timer >= 1.0f){
				timer = 0f;
			}
		}
	}
}
